<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><li class="fa fa-remove"></li></button>
    <h5 class="modal-title"></h5>
</div>

<div class="modal-body">
    <form id="generator_form" name="generator_form" class="form-horizontal">
        <input type="hidden" name="id">
        <input type="hidden" name="version">
        <input type="hidden" name="createDateTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
        <input type="hidden" name="deleted" value="0">
        <input type='hidden' value="${CSRFToken}" id='csrftoken'>
        <div class="box-body">
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">姓名<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请填写姓名">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">性别<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="gender" name="gender" placeholder="请填写性别">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">民族<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <select name="nation.id" id="nation.id" data-code="NATION"  data-flag="dictSelector" data-placeholder="请选择民族" class="form-control select2" style="width:100%" data-blank="true"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">工资<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="salary" name="salary" placeholder="请填写工资">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">是否启用<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <label class="control-label"> <input type="radio" name="enable" data-flag="icheck" class="flat-red" value="1"> 是</label> &nbsp;
                        <label class="control-label"> <input type="radio" name="enable" data-flag="icheck" class="flat-red" value="0"> 否</label>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">编码<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="code" name="code" placeholder="请填写编码">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">生日<span style="color:red">*</span></label>
                    <div class="input-group col-sm-8">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" placeholder="请填写生日" name="birthday" id="birthday" data-flag="datepicker" class="form-control" data-format="yyyy-MM-dd">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">学历<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <select name="education" id="education" data-code="EDUCATION"  data-flag="dictSelector" data-placeholder="请选择学历" class="form-control select2" style="width:100%" data-blank="true"></select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">所在组织<span style="color:red">*</span></label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="department" name="department" placeholder="请填写所在组织">
                    </div>
                </div>
            </div>
        </div>
        <div class="box-footer text-right">
            <button type="button" class="btn btn-default" data-btn-type="cancel" data-dismiss="modal">取消</button>
            <button type="submit" class="btn btn-primary" data-btn-type="save">提交</button>
        </div>
    </form>
</div>
<script>
    var form;
    var id="${id?default(0)}";
    $(function(){
        //初始化表单
        form=$("#generator_form").form();
        //数据校验
        $("#generator_form").bootstrapValidator({
            message : '请输入有效值',
            feedbackIcons : {
                valid : 'glyphicon glyphicon-ok',
                invalid : 'glyphicon glyphicon-remove',
                validating : 'glyphicon glyphicon-refresh'
            },
            submitHandler : function() {
                modals.confirm('确认保存？', function() {
                    var generator = form.getFormSimpleData();
                    ajaxPost(basePath+'/generator/save',{"obj":JSON.stringify(generator)}, function(data) {
                        if(data.success){
                            if(id!="0"){
                                modals.hideWin(winId);
                                generatorTable.reloadRowData(id);
                            }else{
                                modals.hideWin(winId);
                                generatorTable.reloadData();
                            }
                        }
                    });
                });
            },
            fields : {
                "name":{
                    validators:{
                        notEmpty:{message:'姓名不能为空'}
                    }
                },
                "code":{
                    validators:{
                        notEmpty:{message:'编码不能为空'}
                    }
                },
                "gender":{
                    validators:{
                        notEmpty:{message:'性别不能为空'}
                    }
                },
                "birthday":{
                    validators:{
                        notEmpty:{message:'生日不能为空'},
date:{format:$(this).data('format'),message:'请输入有效生日'}
                    }
                },
                "nation.id":{
                    validators:{
                        notEmpty:{message:'民族不能为空'}
                    }
                },
                "education":{
                    validators:{
                        notEmpty:{message:'学历不能为空'}
                    }
                },
                "salary":{
                    validators:{
                        notEmpty:{message:'工资不能为空'},
numeric:{message:'工资是数字类型'}
                    }
                },
                "department":{
                    validators:{
                        notEmpty:{message:'所在组织不能为空'}
                    }
                },
                "enable":{
                    validators:{
                        notEmpty:{message:'是否启用不能为空'}
                    }
                }
            }
        });
        //初始化控件
        form.initComponent();
        //编辑回填
        if(id!=0){
            ajaxPost(basePath+"/generator/get/"+id,null,function(data){
                form.initFormData(data);
            })
        }
    });

</script>
